// Commands.cpp : Implementation of CCommands
#include "stdafx.h"
#include "MouseGestureAddIn.h"
#include "Commands.h"

#include "MouseTracer.h"
#include "MGConfigurationDialog.h"
#include "HRX.h"

/////////////////////////////////////////////////////////////////////////////
// CCommands

CCommands::CCommands()
{
}

/////////////////////////////////////////////////////////////////////////////
// ICommands

STDMETHODIMP CCommands::MouseGestureToggle()
{
	HRX2 hrx2(S_OK);
	try
	{
		hrx2 = m_piApplication->EnableModeless(VARIANT_FALSE);
		if (!MGCfg::Get().Option().IsMGEnabled())
		{
			MGCfg::Get().UpdateRegistry(FALSE);
			MGCfg::Get().Option().EnableMG(TRUE);
			MGCfg::Get().UpdateRegistry(TRUE);
			MouseTracer::Setup( _Module.GetModuleInstance() );
			
			::MessageBox( AfxGetMainWnd()->GetSafeHwnd(), _T("Mouse Gesture has been enabled"), _T("Mouse Gesture Add-In"), MB_OK );
		}
		else
		{
			if( IDYES == ::MessageBox( AfxGetMainWnd()->GetSafeHwnd(), _T("Mouse Gesture is currently enabled.\nDo you want to disable it?"), _T("Mouse Gesture Add-In"), MB_YESNO) )
			{
				MGCfg::Get().UpdateRegistry(FALSE);
				MGCfg::Get().Option().EnableMG(FALSE);
				MGCfg::Get().UpdateRegistry(TRUE);
				MouseTracer::Remove();
			}
		}
		hrx2 = m_piApplication->EnableModeless(VARIANT_TRUE);
	}
	catch(HRESULT hr)
	{
		ASSERT(FALSE);
		return hr;
	}
	catch(...)
	{
		ASSERT(FALSE);
	}
	
	return hrx2;
}

STDMETHODIMP CCommands::MouseGestureConfigure()
{
	// TODO: Add your implementation code here
	HRX2 hrx2(S_OK);
	try
	{
		hrx2 = m_piApplication->EnableModeless(VARIANT_FALSE);
		CMGConfigurationDialog dlg;
		dlg.DoModal();
		hrx2 = m_piApplication->EnableModeless(VARIANT_TRUE);
	}
	catch(HRESULT hr)
	{
		ASSERT(FALSE);
		return hr;
	}
	catch(...)
	{
		ASSERT(FALSE);
	}
	
	return hrx2;
}
